#coding=utf-8
from django.db import models
from BaiduMap_JS.models import SelectPositionField
from DjangoBbs.BbsTheme.models import BbsTheme
from DjangoUeditor.models import UEditorField
from PublicTool.BaseModel import Base_UserModel, Base_TimeModel

__author__ = 'czq'
class Province(models.Model):
    name=models.CharField(u"省",max_length=10)
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '省份'
        verbose_name_plural = '省份'

class City(models.Model):
    name=models.CharField(u"省",max_length=10)
    province=models.ForeignKey(Province,verbose_name=u"省")
    cityCode=models.IntegerField(u"城市代码",default=0)
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '城市'
        verbose_name_plural = '城市'


class District(models.Model):
    name=models.CharField(u"区",max_length=10)
    city=models.ForeignKey(City,verbose_name=u"城市")
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '区'
        verbose_name_plural = '区'



class PositionType(Base_UserModel):
    POS_TYPE_START=0
    POS_TYPE_MIDDLE=1
    POS_TYPE_END=2
    POS_TYPE_SELECT=(
        (POS_TYPE_START, '起点'),
        (POS_TYPE_MIDDLE, '行程中'),
        (POS_TYPE_END, '终点'),
    )

    name=models.CharField(u"名称",max_length=10)
    rank=models.IntegerField(u"排序",default=0)
    type=models.IntegerField(u"类型",choices=POS_TYPE_SELECT,default=0)

    #City=models.ForeignKey(City,verbose_name=u"城市")
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '位置类型'
        verbose_name_plural = '位置类型'
        ordering=['-rank']


class LineType(Base_UserModel):
    name=models.CharField(u"名称",max_length=10)
    rank=models.IntegerField(u"排序",default=1)
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '线路类型'
        verbose_name_plural = '线路类型'
        ordering=['rank']



class RideLine(Base_TimeModel):
    ##1为正式发布，2为草稿箱
    #    # 文章发布状态
    #CONTENT_STATUS_PUBLISHED = 1
    ## 文章草稿箱状态
    #CONTENT_STATUS_DRAFT = 2
    ##私密
    #CONTENT_STATUS_PRIVATE = 3
    ## 文章状态选项
    #CONTENT_STATUS_CHOICES = (
    #    (CONTENT_STATUS_PUBLISHED, '发布'),
    #    (CONTENT_STATUS_DRAFT, '草稿箱'),
    #    (CONTENT_STATUS_PRIVATE, '私密日志'),
    #)
    #status = models.PositiveSmallIntegerField('状态',
    #                             choices=CONTENT_STATUS_CHOICES,
    #                             default=CONTENT_STATUS_PUBLISHED)

    #LINE_TYPE_GO=0
    #LINE_TYPE_GO=1
    #LINE_TYPE_SELECT=(
    #    (LINE_TYPE_GO, '去往'),
    #    (LINE_TYPE_GO, '回程'),
    #)

    #name = models.CharField(u"标题",max_length=100)
    #content=UEditorField(u'内容',height=200,width=600,imagePath="RideLine",imageManagerPath="RideLine",filePath="RideLine",blank=True,null=True)
    theme=models.OneToOneField(BbsTheme,verbose_name=u'主题')
    lineType=models.ForeignKey(LineType,verbose_name=u"线路类型")
    startPosition=models.IntegerField(u"起点",null=True,blank=True)
    startTime=models.DateTimeField(u"出发时间",null=True,blank=True)
    endPosition=models.IntegerField(u"终点",null=True,blank=True)
    endTime=models.DateTimeField(u"到达时间",null=True,blank=True)

    def __unicode__(self):
        return self.theme.title
    class Meta:
        verbose_name = '线路'
        verbose_name_plural = '线路'
        ordering = ['-addTime']

class Position(Base_TimeModel):
    longitude=models.FloatField(u"经度")
    latitude=models.FloatField(u"纬度")
    city=models.ForeignKey(City,verbose_name=u"城市",null=True,blank=True)
    address=SelectPositionField(verbose_name=u"位置",max_length=100,null=True,blank=True,dialog_height='450px',dialog_width ='400px')
    class Meta:
        verbose_name = '位置'
        verbose_name_plural = '位置'
class Vehicle(models.Model):
    name = models.CharField(u"名称",max_length=50)
    rank=models.PositiveSmallIntegerField(u'排序',default=1)
    def __unicode__(self):
        return self.name
    class Meta:
        verbose_name = '交通工具'
        verbose_name_plural = '交通工具'
        ordering = ['-rank']
class RidePosition(Position):
    #travelLine=models.ForeignKey(RideLine,verbose_name=u"线路",null=True,blank=True)
    theme=models.ForeignKey(BbsTheme,verbose_name=u'主题')
    content=UEditorField(u'内容',height=200,width=600,imagePath="RidePosition",imageManagerPath="RidePosition",filePath="RidePosition",blank=True,null=True)
    arriveTime=models.DateTimeField(u"到达时间",null=True,blank=True,help_text=u'到达这个位置的时间')
    departureTime=models.DateTimeField(u"出发时间",null=True,blank=True,help_text=u'开始去下一个位置的时间')

    vehicle=models.ForeignKey(Vehicle,verbose_name=u'交通工具')
    #lastPosition=models.ForeignKey('self',verbose_name=u"上一个位置",null=True,blank=True)

    positionType=models.ForeignKey(PositionType,verbose_name=u"位置类型")
    rank=models.IntegerField(u"排序",default=1)
    #positionType=models.IntegerField(u"路段",choices=POS_TYPE_SELECT,default=POS_TYPE_MIDDLE)
    #lastPosition=models.ForeignKey('self',verbose_name=u"上一个地点",related_name='lastPosition',null=True,blank=True)
    #nextPosition=models.ForeignKey('self',verbose_name=u"下一个地点",related_name='nextPosition',null=True,blank=True)
    def __unicode__(self):
        return self.address
    class Meta:
        verbose_name = '位置'
        verbose_name_plural = '位置'
